<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form ref="form" :model="form" label-width="110px" :rules="rules">
          <el-form-item label="输入端口：" prop="inPort">
            <el-input v-model="form.inPort" size="small" clearable></el-input>
          </el-form-item>
          <el-form-item label="输出端口：" prop="outPort">
            <el-input v-model="form.outPort" size="small" clearable></el-input>
          </el-form-item>
          <el-form-item label="功能说明：" prop="funDescription">
            <el-input
              type="textarea"
              v-model="form.funDescription"
              :autosize="{ minRows: 3, maxRows: 8 }"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注：" prop="remarks">
            <el-input
              type="textarea"
              v-model="form.remarks"
              :autosize="{ minRows: 3, maxRows: 8 }"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="高校测试模型：" prop="modelCode">
                <el-select v-model="form.modelCode" placeholder="请选择">
                  <el-option
                    v-for="item in modelSelection"
                    :key="item.optCode"
                    :label="item.optName"
                    :value="item.optCode"
                  ></el-option>
                </el-select>
              </el-form-item> -->
          <el-form-item class="form-btn-row">
            <mine-button type="primary" @click="onCancel" secondary
              >取 消
            </mine-button>
            <mine-button type="primary" @click="onSubmit">保 存 </mine-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import request from "@/modules/index/utils/request";
import qs from "qs";

export default {
  name: "addHelp",
  props: {
    rowData: {
      type: Object,
    },
    paramId: {
      type: String,
    },
  },
  data() {
    return {
      form: {},
      rules: {},
    };
  },
  watch: {
    // 编辑时回显
    "rowData.id": {
      handler(val) {
        this.form = this.rowData;
      },
      immediate: true,
    },
  },
  methods: {
    async onSubmit() {
      let res = {};
      // 如果props中rowData有值，则走编辑接口
      if (this.rowData.id) {
        res = await this.$store.dispatch(
          "helpInfo/helpInfoParamUpdate",
          this.form
        );
      } else {
        this.form.helpId = this.paramId;
        res = await this.$store.dispatch(
          "helpInfo/helpInfoParamSave",
          this.form
        );
      }
      if (res.data.status === 200) {
        this.form = {};
        this.$message.success(res.data.msg);
        this.$emit("changeFlag");
      } else {
        this.$message.warning("保存失败！");
      }
    },
    onCancel() {
      this.form = {};
    },
  },
  created() {},
};
</script>

<style scoped>
</style>